package com.warren.test;

import io.swagger.models.auth.In;

import java.util.*;

/**
 * @version V1.0
 * @Description:
 * @author: warren
 * @date: 2022/7/25$ 16:24$
 */
public class GenericDemo {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        c.add("hello");
        c.add("say");
        c.add("warren");
//        c.add(10); //ClassCastException

        Iterator it = c.iterator();
        while (it.hasNext()) {
            String s = (String) it.next();
            System.out.println(s);
        }

        Generic<String> stringGeneric = new Generic<>();
        stringGeneric.setT("hallo");
        System.out.println(stringGeneric);

        Generic<Integer> objectGeneric = new Generic<>();
        objectGeneric.setT(10);
        System.out.println(objectGeneric);

        Generic1 generic1 = new Generic1();
        generic1.show("hello");
        generic1.show(1);
        int sum = generic1.sum(1, 2, 3);
        System.out.println(sum);

        //可变参数使用
        //返回由指定数组支持的固定大小的列表(不允许添加)
        List<String> strings = Arrays.asList("1", "2");
        //返回包含任意元素的不可变列表
//        List<String> strings1 = List.of("1", "2");
//        Set<String> set = Set.of("1", "2");
    }
}
